package com.hx.learn.tx.spring.service.impl;

import com.hx.learn.tx.spring.mapper.BookMapper;
import com.hx.learn.tx.spring.model.Book;
import com.hx.learn.tx.spring.service.BookService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * @author jxlgcmh
 * @date 2020-05-17 17:26
 * @description
 */
public class BookServiceImpl implements BookService {

    // 不能再使用注解自动注入

    private BookMapper bookMapper;

    /**
     * 使用构造方法的方式注入
     * @param bookMapper
     */
    public void setBookMapper(BookMapper bookMapper) {
        this.bookMapper = bookMapper;
    }

    @Override
    public Book getBook(String bookName) {
        throw new UnsupportedOperationException();
    }

    @Override
    public Book getBookById(Integer id) {
        return bookMapper.queryBookById(id);
    }

    @Override
    public List<Book> getAllBook() {
       // throw new UnsupportedOperationException();
        return bookMapper.queryAllBook();
    }

    @Override
    public void insertBook(Book book) {
        bookMapper.addBook(book);
    }

    @Override
    public void updateBook(Book book) {
            bookMapper.updateBook(book);
            int a =1/0;
    }
}
